package com.zk.babala.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

import com.zk.babala.activity.IndexActivity;
import com.zk.babala.util.HistoryUtil;

/**
 * @Author: zhangke
 * @Date: 2025/8/20 17:46
 */
public class BootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        // 检查是否是开机启动意图
        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            // 读取设置，检查是否启用了开机进入直播功能
            if (HistoryUtil.getHistoryInstance().getBootToApp()) {
                Intent indexIntent = new Intent(context, IndexActivity.class);
                indexIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                // Android 10及以上版本可能需要额外处理
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                    indexIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
                }
                context.startActivity(indexIntent);
            }
        }
    }
}
